import subprocess as sp
import os
os.system("g++ sol.cpp -o sol")
os.system("g++ brute.cpp -o brute")
os.system("g++ gen.cpp -o gen")

n = int(input())
lst = []
for i in range(n):
    p = sp.Popen(f"./gen > dt/{i}.in && ./sol < dt/{i}.in > dt/{i}.out && ./brute < dt/{i}.in > dt/{i}.ans",shell=True)
    lst.append(p)

for i in range(n):
    lst[i].wait()
    with open(f"dt/{i}.ans","r") as f1:
        with open(f"dt/{i}.out","r") as f2:
            v1 = f1.read()
            v2 = f2.read()
            print(i,v1 == v2)